﻿using System;
using System.Text;
using HslCommunication.BasicFramework;
using Newtonsoft.Json;

namespace HslCommunication.Profinet.Toledo
{
	/// <summary>
	/// 托利多标准格式的数据类对象
	/// </summary>
	// Token: 0x02000046 RID: 70
	public class ToledoStandardData
	{
		/// <summary>
		/// 实例化一个默认的对象
		/// </summary>
		// Token: 0x060005D3 RID: 1491 RVA: 0x00015527 File Offset: 0x00013727
		public ToledoStandardData()
		{
		}

		/// <summary>
		/// 从缓存里加载一个标准格式的对象
		/// </summary>
		/// <param name="buffer">缓存</param>
		// Token: 0x060005D4 RID: 1492 RVA: 0x0001AE80 File Offset: 0x00019080
		public ToledoStandardData(byte[] buffer)
		{
			this.Weight = float.Parse(Encoding.ASCII.GetString(buffer, 4, 6));
			this.Tare = float.Parse(Encoding.ASCII.GetString(buffer, 10, 6));
			switch (buffer[1] & 7)
			{
			case 0:
				this.Weight *= 100f;
				this.Tare *= 100f;
				break;
			case 1:
				this.Weight *= 10f;
				this.Tare *= 10f;
				break;
			case 3:
				this.Weight /= 10f;
				this.Tare /= 10f;
				break;
			case 4:
				this.Weight /= 100f;
				this.Tare /= 100f;
				break;
			case 5:
				this.Weight /= 1000f;
				this.Tare /= 1000f;
				break;
			case 6:
				this.Weight /= 10000f;
				this.Tare /= 10000f;
				break;
			case 7:
				this.Weight /= 100000f;
				this.Tare /= 100000f;
				break;
			}
			this.Suttle = SoftBasic.BoolOnByteIndex(buffer[2], 0);
			this.Symbol = SoftBasic.BoolOnByteIndex(buffer[2], 1);
			this.BeyondScope = SoftBasic.BoolOnByteIndex(buffer[2], 2);
			this.DynamicState = SoftBasic.BoolOnByteIndex(buffer[2], 3);
			switch (buffer[3] & 7)
			{
			case 0:
				this.Unit = (SoftBasic.BoolOnByteIndex(buffer[2], 4) ? "kg" : "lb");
				break;
			case 1:
				this.Unit = "g";
				break;
			case 2:
				this.Unit = "t";
				break;
			case 3:
				this.Unit = "oz";
				break;
			case 4:
				this.Unit = "ozt";
				break;
			case 5:
				this.Unit = "dwt";
				break;
			case 6:
				this.Unit = "ton";
				break;
			case 7:
				this.Unit = "newton";
				break;
			}
			this.IsPrint = SoftBasic.BoolOnByteIndex(buffer[3], 3);
			this.IsTenExtend = SoftBasic.BoolOnByteIndex(buffer[3], 4);
			this.SourceData = buffer;
		}

		/// <summary>
		/// 为 True 则是净重，为 False 则为毛重
		/// </summary>
		// Token: 0x17000137 RID: 311
		// (get) Token: 0x060005D5 RID: 1493 RVA: 0x0001B13E File Offset: 0x0001933E
		// (set) Token: 0x060005D6 RID: 1494 RVA: 0x0001B146 File Offset: 0x00019346
		public bool Suttle { get; set; }

		/// <summary>
		/// 为 True 则是正，为 False 则为负
		/// </summary>
		// Token: 0x17000138 RID: 312
		// (get) Token: 0x060005D7 RID: 1495 RVA: 0x0001B14F File Offset: 0x0001934F
		// (set) Token: 0x060005D8 RID: 1496 RVA: 0x0001B157 File Offset: 0x00019357
		public bool Symbol { get; set; }

		/// <summary>
		/// 是否在范围之外
		/// </summary>
		// Token: 0x17000139 RID: 313
		// (get) Token: 0x060005D9 RID: 1497 RVA: 0x0001B160 File Offset: 0x00019360
		// (set) Token: 0x060005DA RID: 1498 RVA: 0x0001B168 File Offset: 0x00019368
		public bool BeyondScope { get; set; }

		/// <summary>
		/// 是否为动态，为 True 则是动态，为 False 则为稳态
		/// </summary>
		// Token: 0x1700013A RID: 314
		// (get) Token: 0x060005DB RID: 1499 RVA: 0x0001B171 File Offset: 0x00019371
		// (set) Token: 0x060005DC RID: 1500 RVA: 0x0001B179 File Offset: 0x00019379
		public bool DynamicState { get; set; }

		/// <summary>
		/// 单位
		/// </summary>
		// Token: 0x1700013B RID: 315
		// (get) Token: 0x060005DD RID: 1501 RVA: 0x0001B182 File Offset: 0x00019382
		// (set) Token: 0x060005DE RID: 1502 RVA: 0x0001B18A File Offset: 0x0001938A
		public string Unit { get; set; }

		/// <summary>
		/// 是否打印
		/// </summary>
		// Token: 0x1700013C RID: 316
		// (get) Token: 0x060005DF RID: 1503 RVA: 0x0001B193 File Offset: 0x00019393
		// (set) Token: 0x060005E0 RID: 1504 RVA: 0x0001B19B File Offset: 0x0001939B
		public bool IsPrint { get; set; }

		/// <summary>
		/// 是否10被扩展
		/// </summary>
		// Token: 0x1700013D RID: 317
		// (get) Token: 0x060005E1 RID: 1505 RVA: 0x0001B1A4 File Offset: 0x000193A4
		// (set) Token: 0x060005E2 RID: 1506 RVA: 0x0001B1AC File Offset: 0x000193AC
		public bool IsTenExtend { get; set; }

		/// <summary>
		/// 重量
		/// </summary>
		// Token: 0x1700013E RID: 318
		// (get) Token: 0x060005E3 RID: 1507 RVA: 0x0001B1B5 File Offset: 0x000193B5
		// (set) Token: 0x060005E4 RID: 1508 RVA: 0x0001B1BD File Offset: 0x000193BD
		public float Weight { get; set; }

		/// <summary>
		/// 皮重
		/// </summary>
		// Token: 0x1700013F RID: 319
		// (get) Token: 0x060005E5 RID: 1509 RVA: 0x0001B1C6 File Offset: 0x000193C6
		// (set) Token: 0x060005E6 RID: 1510 RVA: 0x0001B1CE File Offset: 0x000193CE
		public float Tare { get; set; }

		/// <summary>
		/// 解析数据的原始字节
		/// </summary>
		// Token: 0x17000140 RID: 320
		// (get) Token: 0x060005E7 RID: 1511 RVA: 0x0001B1D7 File Offset: 0x000193D7
		// (set) Token: 0x060005E8 RID: 1512 RVA: 0x0001B1DF File Offset: 0x000193DF
		[JsonIgnore]
		public byte[] SourceData { get; set; }

		/// <inheritdoc />
		// Token: 0x060005E9 RID: 1513 RVA: 0x0001B1E8 File Offset: 0x000193E8
		public override string ToString()
		{
			return string.Format("ToledoStandardData[{0}]", this.Weight);
		}
	}
}
